﻿/*
* ==============================================================================
*
* File name: OperationFactory
* Description: 
*
* Version: 1.0
* Created: 2015-07-07 11:00:52
*
* Author: Your name
* Company: Your company name
*
* ==============================================================================
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OperationLibrary
{
    /// <summary>
    /// 运算工厂类，（到底要实例化谁（创建对象））
    /// 缺点：包含了必要的 判断逻辑，违反开闭
    /// </summary>
    public class OperationFactory
    {
        public static Operation createOperation(string operate)
        {
            Operation oper = null;  //父类对象，子类也适用（里氏替换）
            switch (operate)
            {
                case "+":
                    {
                        oper = new OperationAdd(); //创建加法类
                        break;
                    }
                case "-":
                    {
                        oper = new OperationSub();
                        break;
                    }
                case "*":
                    {
                        oper = new OpertionMul();
                        break;
                    }
                case "/":
                    {
                        oper = new OperationDiv();
                        break;
                    }
                case "sqr":
                    {
                        oper = new OperationSqr();
                        break;
                    }
                case "sqrt":
                    {
                        oper = new OperationSqrt();
                        break;
                    }
                case "+/-":
                    {
                        oper = new OperationReverse();
                        break;
                    }
                default:
                    break;
            }
            return oper;
        }
    }
}
